d_fnc_fillbackpacks = {
	private ["_control", "_bar", "_control2", "_pic","_backpack","_class","_cfg_class","_nbrtransportmaxweapons","_strtransportmaxweapons"];
	disableSerialization;
	_control = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1000;
	lbClear _control;

	_bar = switch (d_side_player) do {
		case west: {d_backpackclasses select 0};
		case resistance: {d_backpackclasses select 0};
		default {d_backpackclasses select 1};
	};

	{_control lbAdd getText (configFile >> "cfgVehicles" >> _x >> "displayName")} forEach _bar;

	_control lbSetCurSel 0;

	_control = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1002;
	_control2 = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1004;
	_backpack = unitBackpack player;
	if (!isNull _backpack) then {
		_class = typeOf _backpack;
		_pic = getText (configFile >> "cfgVehicles" >> _class >> "picture");
		_control ctrlSetText _pic;
		_cfg_class = (configFile >> "cfgVehicles" >> _class);
		_nbrtransportmaxweapons = getNumber (_cfg_class >> "transportmaxweapons");
		_strtransportmaxweapons = if !(isNil "_nbrtransportmaxweapons") then {(localize "MSG_DOM_BACKPACKWEAPON" + format ["%1",_nbrtransportmaxweapons])} else {""};
		_control2 ctrlSetText (localize "MSG_DOM_BACKPACKEQUIPPED" + " " + getText (_cfg_class >> "displayName") + " " + localize "MSG_DOM_BACKPACKMAGAZINE" + format ["%1",getNumber (_cfg_class >> "transportmaxmagazines")] + _strtransportmaxweapons);
	} else {
		_control ctrlSetText "";
		_control2 ctrlSetText "";
	};
};

d_fnc_blselchanged = {
	private ["_selection", "_control", "_selectedIndex", "_bar", "_class", "_pic"];
	disableSerialization;
	_selection = _this select 0;

	_control = _selection select 0;
	_selectedIndex = _selection select 1;

	if (_selectedIndex == -1) exitWith {};

	_bar = switch (d_side_player) do {
		case west: {d_backpackclasses select 0};
		case resistance: {d_backpackclasses select 0};
		default {d_backpackclasses select 1};
	};

	_control = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1001;

	_class = _bar select _selectedIndex;
	_pic = getText (configFile >> "cfgVehicles" >> _class >> "picture");

	_control ctrlSetText _pic;

	_control = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1003;

	_cfg_class = (configFile >> "cfgVehicles" >> _class);
	_nbrtransportmaxweapons = getNumber (_cfg_class >> "transportmaxweapons");
	_strtransportmaxweapons = if !(isNil "_nbrtransportmaxweapons") then {(localize "MSG_DOM_BACKPACKWEAPON" + format ["%1",_nbrtransportmaxweapons])} else {""};
	_control ctrlSetText (getText (_cfg_class >> "displayName") + " " + localize "MSG_DOM_BACKPACKMAGAZINE" + format ["%1",getNumber (_cfg_class >> "transportmaxmagazines")] + _strtransportmaxweapons);
};

d_fnc_take_backpack = {
	private ["_control", "_sel", "_bar", "_typeold", "_oldbpobj", "_dispname","_backpack"];
	disableSerialization;

	_control = (uiNameSpace GetVariable "D_BACKPACK_DIALOG") displayCtrl 1000;

	_sel = lbCurSel _control;

	if (_sel == -1) exitWith {};

	_bar = switch (d_side_player) do {
		case west: {d_backpackclasses select 0};
		case resistance: {d_backpackclasses select 0};
		default {d_backpackclasses select 1};
	};

	_typeold = "";
	_oldbpobj = unitBackpack player;

	if (!isNull _oldbpobj) then {
		_typeold = typeOf _oldbpobj;
		removeBackpack  player;
	};

	player addBackpack (_bar select _sel);

	_dispname = getText (configFile >> "cfgVehicles" >> (_bar select _sel) >> "displayName");
	
	_bp = unitBackpack player;
	if (!isnull _bp) then {
		(localize "MSG_DOM_BACKPACKEQUIPPED" + " " + _dispname) call XfGlobalChat;
		_backpack = unitBackpack player;
		clearWeaponCargoGlobal _backpack;
		clearMagazineCargoGlobal _backpack;
	} else {
		(localize "MSG_DOM_BACKPACKEQUIPFAIL" + " " + _dispname) call XfGlobalChat;
	};
	// [QGVAR(p_o_a2), [GVAR(string_player), _backpack]] call FUNC(NetCallEvent);

	// if (!isNull _oldbpobj) then {
		// [QGVAR(p_o_a2r), [GVAR(string_player), _oldbpobj]] call FUNC(NetCallEvent);
	// };
};


d_fnc_vdsliderchanged = {
	private ["_newvd","_control"];
	disableSerialization;
	_newvd = round (_this select 1);
	_control = (uiNameSpace GetVariable "X_SETTINGS_DIALOG") displayCtrl 1000;
	_control ctrlSetText (localize "MSG_DOM_VIEWDISTANCE" + " " + str(_newvd));
	setViewDistance _newvd;
};